home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4328 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!gibson
  3. From: gibson@netcom.com (Bob Gibson)
  4. Subject: Re: Q: implicit converstion - error?
  5. Message-ID: <gibsonDLyI11.Mo2@netcom.com>
  6. Organization: A number of persons or groups united for some purpose
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. References: <gibsonDLr0rs.AEB@netcom.com> <310cc2a1.11393601@news.compuserve.com>
  9. Date: Mon, 29 Jan 1996 18:58:13 GMT
  10. Sender: gibson@netcom21.netcom.com
  11.  
  12. John Bain (johnb@pivotal-dm.ccmail.compuserve.com) wrote:
  13. ...
  14. : Conversion from char** -> const char ** is not 
  15. : allowed, because it is potentially unsafe.  Consider
  16. : the following code:
  17. :
  18. : --------------------------------------------------
  19. :
  20. : const char c_ch;
  21. :
  22. : const char **pp_c_ch;
  23. : char *p_ch;
  24. :
  25. : pp_c_ch = &p_ch;       // OK _if_ char** -> const char ** allowed
  26. : *pp_c_ch = &c_ch;      // allowed - assigning &<const char> to const char* 
  27. :                        // p_ch now points at c_ch
  28. : *p_ch = 'X';           // OOPS, modified c_ch!
  29. :
  30. : ---------------------------------------------------
  31.  
  32. I don't see where your example explains the problem I described.  The
  33. fact that the calling function considers the thing as a "* * char" is
  34. only relavent is we are using shared memory/multi-threading.
  35.  
  36. If I say that I want to consider a character to which I have an address
  37. as constant, this indicates that I promise not to change it.  The fact
  38. that you can/will change it when I return to you doesn't matter to me.
  39. The fact that it may change outside of the function would only be of
  40. concern to the optimizer (and I guess the user would then identifiy it
  41. as volatile).
  42.  
  43. I don't see why the compilers are complaining...
  44.  
  45. Bob
  46. -- 
  47. O.J. Verdict - The best innocence money can buy
  48.  
  49. Bob Gibson -- gibson@netcom.com
  50.